package router

import (
	"5-28zk/client/client"
	"5-28zk/client/requset"
	"5-28zk/client/response"
	"5-28zk/common/pkg"
	"5-28zk/common/proto/doctor"
	"fmt"
	"github.com/gin-gonic/gin"
)

func Login(c *gin.Context) {
	var data requset.Login
	err := c.ShouldBind(&data)
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	login, err := client.Login(c, &doctor.LoginReq{
		Name:     data.Name,
		Phone:    data.Phone,
		Password: data.Password,
	})
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	response.ResponseSuccess(c, login)
}

func PatientList(c *gin.Context) {
	ui := c.GetUint("userId")
	fmt.Println(ui)
	var data requset.PatientList
	err := c.ShouldBind(&data)
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	list, err := client.PatientList(c, &doctor.PatientListReq{
		DoctorId: int64(ui),
		Status:   int64(data.Status),
	})
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	response.ResponseSuccess(c, list)
}

func PatientShow(c *gin.Context) {
	var data requset.PatientShow
	err := c.ShouldBind(&data)
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	show, err := client.PatientShow(c, &doctor.PatientShowReq{Id: int64(data.Id)})
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	response.ResponseSuccess(c, show)
}

func Upload(c *gin.Context) {
	file, err := c.FormFile("file")
	if err != nil {
		response.ResponseError(c, err.Error())
		return
	}
	if file.Size > 5*1024*1024 {
		response.ResponseError(c, "文件过大")
		return
	}
	dst := "common/status/upload" + file.Filename
	c.SaveUploadedFile(file, dst)
	pkg.Upload(dst, file.Filename)
	response.ResponseSuccess(c, "成功"+pkg.GetUrl(file.Filename))
}
